import 'package:city_corner/commons/my-dio.dart';
import 'package:city_corner/login-page/my-textfield.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../bottom-bar.dart';

class LoginForm extends StatefulWidget {
  final bool register;

  LoginForm({this.register = false});

  @override
  _LoginForm createState() => _LoginForm();
}

class _LoginForm extends State<LoginForm> {
  Map data = {'account': '', 'passwd': '', 'commitPasswd': ''};

  void setValue(String key, String value) {
    data[key] = value;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [
          Container(
            child: Text('City Corner', style: TextStyle(fontSize: 30)),
            margin: EdgeInsets.only(bottom: 50),
          ),
          MyTextField(
              placeholder: '手机号/用户名/邮箱', label: 'account', setValue: setValue),
          MyTextField(placeholder: '密码', label: 'passwd', setValue: setValue),
          ElevatedButton(
            child: Text('登录'),
            onPressed: () {
              // dioPost('/login',
              //         data: {
              //           'account': data['account'],
              //           'passwd': data['passwd']
              //         },
              //         contentType: 'application/x-www-form-urlencoded')
              //     .then((res) {
              //   if (res['status'] == 1) {
              //     Navigator.push(context, MaterialPageRoute(builder: (_) {
              //       return BottomBar();
              //     }));
              //   }
              // });
              Navigator.push(context, MaterialPageRoute(builder: (_) {
                return BottomBar();
              }));
            },
          ),
          Visibility(
            visible: widget.register,
            child: ElevatedButton(
              child: Container(
                  child: Text(
                '注册',
              )),
              onPressed: () {},
            ),
          )
        ],
      ),
    );
  }
}
